define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'service/order/order/index' + location.search,

                    // edit_url: 'service/order/order/edit',

                    multi_url: 'service/order/order/multi',
                    import_url: 'service/order/order/import',
                    table: 'service_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        
                        {field: 'goods_id', title: __('项目信息'),operate: false, cellStyle: function () {return {css: {"min-width": "266px"}}},formatter:function (value,row) {
                            return `
                               <div>
                                <div style="display: flex;align-items: center;justify-content: space-between;color: #666;margin-bottom: 10px;">
        <div>订单编号：${row.orderId}</div>
        <div style="margin-left: 20px;">ID:${row.id}</div>
    </div>
    <div style="display: flex">
        <image style="width: 112px;height: 112px;border-radius: 10px" src="${row.detail.image}"></image>
        <div style="margin-left: 25px;">
            <div style="display: flex;align-items: center;margin-bottom: 8px;">
                <div style="font-size: 16px;font-weight: bold;">${row.detail.name}</div>
                <div style="margin-left: 10px;width: 68px;height: 26px;line-height: 26px;text-align: center;background: rgba(97, 22, 255, 0.10);border-radius: 13px;color: #6116FF;font-size: 12px;">${row.to_shop_text}</div>
            </div>
            <div  style="display: flex;align-items: center;margin-bottom: 6px;">
                <span style="margin-right: 30px;color: #999;font-size: 14px;">规格</span>
                <span style="color: #333;font-size: 14px">${row.detail.sku_name}</span>
            </div>
            <div  style="display: flex;align-items: center;margin-bottom: 6px;">
                <span style="margin-right: 30px;color: #999;font-size: 14px;">数量</span>
                <span style="color: #333;font-size: 14px">X${row.detail.num}</span>
            </div>
            <div  style="display: flex;align-items: center;margin-bottom: 6px;">
                <span style="margin-right: 30px;color: #999;font-size: 14px;">价格</span>
                <span style="color: #333;font-size: 14px">${row.detail.price}</span>
            </div>
        </div>
    </div>
    
</div>
                            `
                            
                        }},
                        
                        {field: 'status', title: __('状态'),operate: false,  cellStyle: function () {return {css: {"width": "200px"}}},formatter:function (value,row){
                            let result = '';
                            if(row.to_shop == 'shop' && row.status == 2){
                                result += ` <div style="height: 58px;width: 196px;background: linear-gradient(90deg, #F0FAF3 0%, rgba(240,250,243,0) 100%);display: flex;
align-items: center;justify-content: flex-start;padding-left: 20px;">
        <span style="color: #999;font-size: 14px;margin-right: 30px;">订单状态</span>
        <span style="color: #62CB81;font-size: 14px;font-weight: bold;">待核销</span>
    </div>`
                            } else {
                                result += `<div style="height: 58px;width: 196px;background: linear-gradient(90deg, #F0FAF3 0%, rgba(240,250,243,0) 100%);display: flex;
align-items: center;justify-content: flex-start;padding-left: 20px;">
        <span style="color: #999;font-size: 14px;margin-right: 30px;">订单状态</span>
        <span style="color: #62CB81;font-size: 14px;font-weight: bold;">${row.status_text}</span>
    </div>`
                            }
                            result += `<div style="height: 58px;width: 196px;background: linear-gradient(90deg, #FFF2F2 0%, rgba(255,242,242,0) 100%);display: flex;
align-items: center;justify-content: flex-start;padding-left: 20px;">
        <span style="color: #999;font-size: 14px;margin-right: 30px;">售后状态</span>
        <span style="color: #62CB81;font-size: 14px;font-weight: bold;">${row.is_service_text}</span>
    </div>
    <div style="height: 58px;width: 196px;background: linear-gradient(90deg, #FFF7E6 0%, rgba(255,247,230,0) 100%);display: flex;
align-items: center;justify-content: flex-start;padding-left: 20px;">
        <span style="color: #999;font-size: 14px;margin-right: 30px;">投诉状态</span>
        <span style="color: #62CB81;font-size: 14px;font-weight: bold;">${row.is_complaint_text}</span>
    </div>`
                            return  result
                            
                        }},
                        
                        
                        {field: 'user_id', title: __('用户信息'),operate: false, cellStyle: function () {return {css: {"min-width": "248px"}}},formatter:function (value,row){
                            let result = `<div>
    <div style="display: flex;align-items: flex-start;">
      <img src="${row.user.avatar}" alt="" style="width: 48px;height: 48px;flex-shrink: 0;border-radius: 50%;">
      <div style="margin-left: 14px;flex: 1;">
        <div style="margin-bottom: 5px;display: flex;justify-content: space-between;">
          <span style="font-size: 16px;color: #333;">${row.user.nickname}</span>
        </div>
        <div style="display: flex;justify-content: space-between;">
          <span style="font-size: 14px;color: #666;">${row.user.mobile}</span>
        </div>`
        if(row.to_shop == 'door'){
            result += ` <div style="font-size: 14px;color: #666;text-align: left;margin-top:10px;">预约信息：${row.address.name+''+row.address.mobile}</div>
    <div style="font-size: 14px;color: #666;margin: 10px 0;text-align: left;">地址：${row.address.province+row.address.city+row.address.district+row.address.area+row.address.address}</div>
    <div style="font-size: 14px;color: #666;text-align: left;">预约时间：${row.starttime_text}</div>
      `
        }else {
            result += `<div style="font-size: 14px;color: #666;text-align: left;margin-top:10px;">核销码：${row.check_name}</div>
                        <div style="font-size: 14px;color: #666;text-align: left;margin-top:10px;">核销二维码：<img style="width:40px;height:40px;" src="${row.qrcode_image}" /></div>
            `
        }
        
        result += `</div></div></div>`
                            return result
                        }},
                        {field: 'shop_id', title: __('服务者/门店信息'),operate: false, cellStyle: function () {return {css: {"min-width": "248px"}}},formatter:function (value,row){
                            if(row.shop && row.skill){
                                return `<div>
                           
    <div style="background: #F7F7F7;padding: 12px;border-radius: 10px;margin-top: 16px;">
        <div style="display: flex;align-items: center;justify-content: center;width: 64px;height: 18px;background: #1677FF;color: #FFF;margin-bottom: 8px;font-size: 12px;border-radius: 2px;">门店信息</div>
        <div style="display: flex;align-items: center;">
            <img src="${row.shop.logo_image}" alt="" style="width: 48px;height: 48px;flex-shrink: 0;border-radius: 50%;">
            <div style="margin-left: 14px;flex: 1;">
                <div style="margin-bottom: 5px;display: flex;justify-content: space-between;">
                    <span style="font-size: 16px;color: #333;">${row.shop.name}</span>
                </div>
                <div style="display: flex;justify-content: space-between;">
                    <span style="font-size: 14px;color: #666;">${row.shop.leader_name+''+row.shop.leader_mobile}</span>
                </div>
            </div>
        </div>
    </div>
    <div style="background: #F7F7F7;padding: 12px;border-radius: 10px;margin-top: 16px;">
        <div style="display: flex;align-items: center;justify-content: center;width: 50px;height: 18px;background: #6116FF;color: #FFF;margin-bottom: 8px;font-size: 12px;border-radius: 2px;">服务者</div>
        <div style="display: flex;align-items: center;">
            <img src="${row.skill.image}" alt="" style="width: 48px;height: 48px;flex-shrink: 0;border-radius: 50%;">
            <div style="margin-left: 14px;flex: 1;">
                <div style="margin-bottom: 5px;display: flex;justify-content: space-between;">
                    <span style="font-size: 16px;color: #333;">${row.skill.name}</span>
                </div>
                <div style="display: flex;justify-content: space-between;">
                    <span style="font-size: 14px;color: #666;">${row.skill.mobile}</span>
                </div>
            </div>
        </div>
    </div>
 
  </div>`
                            }else if(row.skill){
                                return `<div>
    
    <div style="background: #F7F7F7;padding: 12px;border-radius: 10px;margin-top: 16px;">
        <div style="display: flex;align-items: center;justify-content: center;width: 50px;height: 18px;background: #6116FF;color: #FFF;margin-bottom: 8px;font-size: 12px;border-radius: 2px;">服务者</div>
        <div style="display: flex;align-items: center;">
            <img src="${row.skill.image}" alt="" style="width: 48px;height: 48px;flex-shrink: 0;border-radius: 50%;">
            <div style="margin-left: 14px;flex: 1;">
                <div style="margin-bottom: 5px;display: flex;justify-content: space-between;">
                    <span style="font-size: 16px;color: #333;">${row.skill.name}</span>
                </div>
                <div style="display: flex;justify-content: space-between;">
                    <span style="font-size: 14px;color: #666;">${row.skill.mobile}</span>
                </div>
            </div>
        </div>
    </div>
 
  </div>`
                            }else if(row.shop){
                                return `<div>
                                
    <div style="background: #F7F7F7;padding: 12px;border-radius: 10px;margin-top: 16px;">
        <div style="display: flex;align-items: center;justify-content: center;width: 64px;height: 18px;background: #1677FF;color: #FFF;margin-bottom: 8px;font-size: 12px;border-radius: 2px;">门店信息</div>
        <div style="display: flex;align-items: center;">
            <img src="${row.shop.logo_image}" alt="" style="width: 48px;height: 48px;flex-shrink: 0;border-radius: 50%;">
            <div style="margin-left: 14px;flex: 1;">
                <div style="margin-bottom: 5px;display: flex;justify-content: space-between;">
                    <span style="font-size: 16px;color: #333;">${row.shop.name}</span>
                </div>
                <div style="display: flex;justify-content: space-between;">
                    <span style="font-size: 14px;color: #666;">${row.shop.leader_name+''+row.shop.leader_mobile}</span>
                </div>
            </div>
        </div>
    </div>
    
</div>`
                            }else {
                                return ''
                            }
                            
                        }},
                        
                        {field: 'price', title: __('付款信息'),operate: false, cellStyle: function () {return {css: {"min-width": "108px"}}},formatter:function (value,row){
                            return `<div>
      
      <div style="display:flex;align-items: center;margin-bottom: 10px;">
        <div style="color: #999999;font-size: 14px;width: 72px;text-align:right;margin-right:20px;">总计</div>
        <div style="color: #E4484B;font-size: 18px;font-weight: bold;">${row.payprice}</div>
    </div>
    <div style="display:flex;align-items: center;margin-bottom: 6px;">
        <div style="color: #999999;font-size: 14px;width: 72px;text-align:right;margin-right:20px;">项目费</div>
        <div style="color: #3C78FF;font-size: 14px;">${row.price}</div>
    </div>
    <div style="display:flex;align-items: center;margin-bottom: 6px;">
        <div style="color: #999999;font-size: 14px;width: 72px;text-align:right;margin-right:20px;">项目折扣</div>
        <div style="color: #3C78FF;font-size: 14px;">${row.discount/10}</div>
    </div>
    <div style="display:flex;align-items: center;margin-bottom: 6px;">
        <div style="color: #999999;font-size: 14px;width: 72px;text-align:right;margin-right:20px;">优惠券</div>
        <div style="color: #3C78FF;font-size: 14px;">${row.coupon_price}</div>
    </div>
    <div style="display:flex;align-items: center;margin-bottom: 6px;">
        <div style="color: #999999;font-size: 14px;width: 72px;text-align:right;margin-right:20px;">车费</div>
        <div style="color: #3C78FF;font-size: 14px;">${row.travel_price}</div>
    </div>
    <div style="display:flex;align-items: center;margin-bottom: 6px;">
        <div style="color: #999999;font-size: 14px;width: 72px;text-align:right;margin-right:20px;">补差价</div>
        <div style="color: #3C78FF;font-size: 14px;">${row.premium_price}</div>
    </div>
    <div style="display:flex;align-items: center;margin-bottom: 6px;">
        <div style="color: #999999;font-size: 14px;width: 72px;text-align:right;margin-right:20px;">加项费</div>
        <div style="color: #3C78FF;font-size: 14px;">${row.add_price}</div>
    </div>
    <div style="display:flex;align-items: center;">
        <div style="color: #999999;font-size: 14px;width: 72px;text-align:right;margin-right:20px;">退款金额</div>
        <div style="color: #3C78FF;font-size: 14px;">${row.refund_price}</div>
    </div>
      
    </div>`
                            
                        }},
                         {field: 'id', title: __('财务'),operate: false, cellStyle: function () {return {css: {"min-width": "250px"}}},formatter:function (value,row){
                             if(row.is_settle == 2){
                                 let result = `
    <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
        <span style="font-size: 14px;color: #999;">付款方式</span>
        <span style="color: #3C78FF;font-size: 14px;">${row.paytype_text}</span>
    </div>
    <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
        <span style="font-size: 14px;color: #999;">服务者佣金</span>
        <span style="color: #3C78FF;font-size: 14px;">${row.skillRebate || 0}</span>
    </div>`
    if(row.shop_id > 0){
        result +=`
    <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-top: 1px solid #EEEEEE;">
        <span style="font-size: 14px;color: #999;">商户佣金</span>
        <span style="color: #3C78FF;font-size: 14px;">${row.shopRebate}</span>
    </div>
                            `
    }
                                return result
                             }else {
                                  let result = `
    <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
        <span style="font-size: 14px;color: #999;">付款方式</span>
        <span style="color: #3C78FF;font-size: 14px;">${row.paytype_text}</span>
    </div>                              
    <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
        <span style="font-size: 14px;color: #999;">服务者佣金</span>
        <span style="color: #3C78FF;font-size: 14px;">${row.is_settle_text}</span>
    </div>`
    if(row.shop_id > 0){
        result +=`
    <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-top: 1px solid #EEEEEE;">
        <span style="font-size: 14px;color: #999;">商户佣金</span>
        <span style="color: #3C78FF;font-size: 14px;">${row.is_settle_text}</span>
    </div>
                            `
    }
                                return result
                                 
                             }
                            
                        }},
                         {field: 'id', title: __('时间'),operate: false, cellStyle: function () {return {css: {"min-width": "180px"}}},formatter:function (value,row){
                            return `
                           <div style="margin-bottom: 10px;">
        <div style="color: #999999;font-size: 14px;margin-bottom: 8px;text-align:left;">创建时间</div>
        <div style="color: #333333;font-size: 14px;text-align:left;">${row.create_time}</div>
    </div>
    <div style="margin-bottom: 10px;">
        <div style="color: #999999;font-size: 14px;margin-bottom: 8px;text-align:left;">支付时间</div>
        <div style="color: #333333;font-size: 14px;text-align:left;">${row.paytime_text}</div>
    </div>
     <div>
        <div style="color: #999999;font-size: 14px;margin-bottom: 8px;text-align:left;">预约时间</div>
        <div style="color: #333333;font-size: 14px;text-align:left;">${row.starttime_text}</div>
    </div>
                            `
                        }},
                        // {checkbox: true},
                        {field: 'id', title: __('Id'),visible: false},
                        {field: 'orderId', title: __('Orderid'), operate: 'LIKE', width:148,visible: false},
                       
                        
                        // {field: 'reach_images', title: __('Reach_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        // {field: 'finish_images', title: __('Finish_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'user_id', title: __('User_id'),visible: false},
                        {field: 'skill_id', title: __('Skill_id'),visible: false},
                        {field: 'shop_id', title: __('Shop_id'),visible: false},
                        {field: 'goods_id', title: __('Goods_id'),visible: false},
                        {field: 'traveltype', title: __('Traveltype'), searchList: {"0":__('Traveltype 0'),"1":__('Traveltype 1'),"2":__('Traveltype 2')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'choose_skill_type', title: __('Choose_skill_type'), searchList: {"0":__('Choose_skill_type 0'),"1":__('Choose_skill_type 1')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'paytype', title: __('Paytype'), searchList: {"0":__('Paytype 0'),"1":__('Paytype 1'),"2":__('Paytype 2'),"3":__('Paytype 3'),"4":__('Paytype 4')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'to_shop', title: __('To_shop'), searchList: {"door":__('To_shop door'),"shop":__('To_shop shop')}, formatter: Table.api.formatter.normal,visible: false},
                        
                        {field: 'price', title: __('Price'), operate:'BETWEEN',visible: false},
                        // {field: 'distance', title: __('Distance'), operate:'BETWEEN'},
                        // {field: 'travel_price', title: __('Travel_price'), operate:'BETWEEN'},
                        // {field: 'sumprice', title: __('Sumprice'), operate:'BETWEEN'},
                        // {field: 'goods_total_price', title: __('Goods_total_price'), operate:'BETWEEN'},
                        // {field: 'discount', title: __('Discount')},
                        // {field: 'coupon_id', title: __('Coupon_id')},
                        // {field: 'coupon_price', title: __('Coupon_price'), operate:'BETWEEN'},
                        // {field: 'premium_price', title: __('Premium_price'), operate:'BETWEEN'},
                        // {field: 'add_price', title: __('Add_price'), operate:'BETWEEN'},
                        {field: 'payprice', title: __('Payprice'), operate:'BETWEEN',visible: false},
                        {field: 'act_travel_price', title: __('Act_travel_price'), operate:'BETWEEN',visible: false},
                        {field: 'refund_price', title: __('Refund_price'), operate:'BETWEEN',visible: false},
                        {field: 'settle_price', title: __('Settle_price'), operate:'BETWEEN',visible: false},
                        {field: 'total_cost_seconds', title: __('Total_cost_seconds'),visible: false},
                        {field: 'starttime', title: __('Starttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},
                        //{field: 'actendtime', title: __('Actendtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'trade_no', title: __('Trade_no'), operate: 'LIKE'},
                        {field: 'memo', title: __('Memo'), operate: 'LIKE',visible: false},
                        {field: 'qrcode_image', title: __('Qrcode_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image,visible: false},
                        {field: 'check_name', title: __('Check_name'),visible: false},
                        {field: 'is_service', title: __('Is_service'), searchList: {"0":__('Is_service 0'),"1":__('Is_service 1'),"2":__('Is_service 2'),"-1":__('Is_service -1')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'is_complaint', title: __('Is_complaint'), searchList: {"0":__('Is_complaint 0'),"1":__('Is_complaint 1')}, formatter: Table.api.formatter.normal,visible: false},
                        //{field: 'is_pool', title: __('Is_pool'), searchList: {"0":__('Is_pool 0'),"1":__('Is_pool 1')}, formatter: Table.api.formatter.normal},
                        {field: 'is_settle', title: __('Is_settle'), searchList: {"0":__('Is_settle 0'),"1":__('Is_settle 1'),"2":__('Is_settle 2')}, formatter: Table.api.formatter.normal,visible: false},
                        // {field: 'reach_images', title: __('Reach_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        // {field: 'finish_images', title: __('Finish_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4'),"5":__('Status 5'),"6":__('Status 6'),"7":__('Status 7'),"-1":__('Status -1')}, formatter: Table.api.formatter.status,visible: false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('订单详情'),
                                    title: __('订单详情'),
                                    classname: 'btn btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-detail',
                                    url: function(row){
                                        return 'service/order/order/info?ids='+row.id;
                                    },

                                },
                                {
                                    name: 'users',
                                    text: __('分配商户'),
                                    title: __('分配商户'),
                                    classname: 'btn btn-xs btn-change btn-dialog',
                                    url: function(row){
                                        return 'service/order/order/updateshop?ids='+row.id;
                                    },
                                    visible:function(row){
                                        if(row.status == 1 && !row.shop_id && !row.skill_id  && (row.is_service == 0 || row.is_service == -1)){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'users',
                                    text: __('分配服务者'),
                                    title: __('分配服务者'),
                                    classname: 'btn btn-xs btn-change btn-dialog',
                                  
                                    url: function(row){
                                        return 'service/order/order/updateskill?ids='+row.id;
                                    },
                                    visible:function(row){
                                        if(row.status == 1 && !row.skill_id  && row.to_shop == 'door' && (row.is_service == 0 || row.is_service == -1)){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'users',
                                    text: __('更换服务者'),
                                    title: __('更换服务者'),
                                    classname: 'btn btn-xs btn-change btn-dialog',

                                    url: function(row){
                                        return 'service/order/order/updateskill?ids='+row.id;
                                    },
                                    visible:function(row){
                                        if(row.skill_id && (row.status == 1 || row.status == 2) && (row.is_service == 0 || row.is_service == -1)){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'accept',
                                    text: __('订单接取'),
                                    title: __('订单接取'),
                                    classname: 'btn btn-xs btn-status btn-ajax',
                                    
                                    url: 'service/order/order/handleOrder?state=2',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger('click');
                                    },
                                    visible:function(row){
                                        if((row.skill_id) && row.status === 1 && (row.is_service == 0 || row.is_service == -1)){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'go',
                                    text: __('服务者出发'),
                                    title: __('服务者出发'),
                                    classname: 'btn btn-xs btn-status btn-ajax',
                                    
                                    url: 'service/order/order/handleOrder?state=3',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger('click');
                                    },
                                    visible:function(row){
                                        if(row.status === 2 && row.to_shop == 'door' && (row.is_service == 0 || row.is_service == -1)){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'check',
                                    text: __('订单已核销'),
                                    title: __('订单已核销'),
                                    classname: 'btn btn-xs btn-status btn-ajax',
                                   
                                    url: 'service/order/order/handleOrder?state=6',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger('click');
                                    },
                                    visible:function(row){
                                        if(row.status === 2 && row.to_shop == 'shop' && (row.is_service == 0 || row.is_service == -1)){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: '',
                                    text: __('服务者到达'),
                                    title: __('服务者到达'),
                                    classname: 'btn btn-xs btn-status btn-ajax',
                                    
                                    url: 'service/order/order/handleOrder?state=4',
                                    success: function (data, ret) {
                                         $(".btn-refresh").trigger('click');
                                    },
                                    visible:function(row){
                                        if(row.status === 3 && row.to_shop == 'door' && (row.is_service == 0 || row.is_service == -1)){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: '',
                                    text: __('开始服务'),
                                    title: __('开始服务'),
                                    classname: 'btn btn-xs btn-status btn-ajax',
                                    
                                    url: 'service/order/order/handleOrder?state=5',
                                    success: function (data, ret) {
                                         $(".btn-refresh").trigger('click');
                                    },
                                    visible:function(row){
                                        if(row.status === 4 && row.to_shop == 'door' && (row.is_service == 0 || row.is_service == -1)){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: '',
                                    text: __('服务完成'),
                                    title: __('服务完成'),
                                    classname: 'btn btn-xs btn-status btn-ajax',
                                    
                                    url: 'service/order/order/handleOrder?state=6',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger('click');
                                    },
                                    visible:function(row){
                                        if(row.status === 5 && (row.is_service == 0 || row.is_service == -1)){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'comment',
                                    text: __('订单评价'),
                                    title: __('订单评价'),
                                    classname: 'btn btn-xs btn-success btn-comment btn-dialog',
                                    
                                    url: function(row){
                                        return 'service/order/comment/index?order_id='+row.id;
                                    },
                                    visible:function(row){
                                        if(row.status === 7){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'refund',
                                    text: __('退款'),
                                    title: __('退款'),
                                    classname: 'btn btn-xs btn-cancel btn-dialog',
                                   
                                    url: function(row){
                                        return 'service/order/order/refund?ids='+row.id;
                                    },
                                    hidden:function(row){
                                        if(row.is_settle === 2  || row.is_service === 2 || row.status == -1 || row.status == 0){
                                            return true;
                                        }
                                    }

                                },
                            ],
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'service/order/order/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'service/order/order/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'service/order/order/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        updateshop: function () {
            
            $(document).on('click', '.btn-embossed', function () {
                parent.$(".btn-refresh").trigger('click');
            });
            Controller.api.bindevent();
        },
        updateskill: function () {
            
            $(document).on('click', '.btn-embossed', function () {
                parent.$(".btn-refresh").trigger('click');
            });
            Controller.api.bindevent();
        },
        refund: function () {
            
            $(document).on('click', '.btn-embossed', function () {
                parent.$(".btn-refresh").trigger('click');
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
